import Vue from "vue";
import Vuex from "vuex";
import getters from "./getters";

// 引入模块
import goods from "./modules/goods";
import address from "./modules/address";

// 持久化
import persistence from "vuex-uniapp-persistence";

Vue.use(Vuex);

const store = new Vuex.Store({
  // 持久化
  plugins: [persistence()],

  state: {
    safeArea: uni.getWindowInfo().safeArea,
    capButton: uni.getMenuButtonBoundingClientRect(),
    historyList: [],
    token: "",
    userInfo: {},
  },
  getters,
  mutations: {
    getHistory(state, payLoad) {
      state.historyList = payLoad;
    },
    setToken(state, token) {
      state.token = token;
    },
    setUserInfo(state,userInfo){
      state.userInfo = userInfo
    }
  },
  modules: {
    goods,
    address,
  },
});

export default store;
